#include "aboutpage.h"
#include "ui_aboutpage.h"
#include <QIcon>
#include <QMouseEvent>

AboutPage * AboutPage::ap = nullptr;
AboutPage::AboutPage(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::AboutPage)
{
    ui->setupUi(this);
    //设置属性
    this->setWindowTitle("关于");
    this->setWindowIcon(QIcon(":/images/aboutlogo.png"));
    //隐藏标题栏、边框
    this->setWindowFlags(
                    Qt::FramelessWindowHint|
                    Qt::WindowMinimizeButtonHint);
    //背景透明
    this->setAttribute(Qt::WA_TranslucentBackground);
    //显示图标
    QPixmap pix;
    pix.load(":/images/aboutlogo.png");
    ui->labLogo->setPixmap(pix.scaled(ui->labLogo->width(), ui->labLogo->height()));
}

AboutPage::~AboutPage()
{
    delete ui;
}

AboutPage *AboutPage::getObject()
{
    if(ap == nullptr)
        ap = new AboutPage;
    return ap;
}

void AboutPage::mousePressEvent(QMouseEvent *event)
{
    //记录起始坐标
    oldPos = event->pos();
    //开始移动
    isMove = true;
}

void AboutPage::mouseReleaseEvent(QMouseEvent *event)
{
    //停止移动
    isMove = false;
}

void AboutPage::mouseMoveEvent(QMouseEvent *event)
{
    //移动
    if(!isMove)
        return;
    this->move(this->pos() + event->pos() - oldPos);
}

void AboutPage::on_btnExit_clicked()
{
    this->hide();
}
